import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class CountDownlatch {
    public static void main(String[] args) {
        CountDownLatch countDownLatch = new CountDownLatch(2);

        ExecutorService pool= Executors.newFixedThreadPool(4);
        pool.execute(new work(countDownLatch));
        pool.execute(new work(countDownLatch));
        pool.execute(new boss(countDownLatch));

        pool.shutdown();
    }
}


class  work implements Runnable{
    CountDownLatch countDownlatch;

    work(CountDownLatch countDownlatch){
        this.countDownlatch=countDownlatch;
    }

    @Override
    public void run() {
        try {
            Thread.sleep(3000);
            System.out.println(Thread.currentThread().getName()+"working");
            countDownlatch.countDown();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }
}

class boss implements Runnable{
    CountDownLatch countDownLatch;
    boss(CountDownLatch countDownLatch){
        this.countDownLatch=countDownLatch;
    }

    @Override
    public void run() {
        try {
            countDownLatch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("boss coming");
    }
}

